import axios from 'axios'
import store from '../store'

const allowToken = ['/login']

// 请求拦截器
axios.interceptors.request.use(config => {
  config.baseURL = 'http://localhost:9090/v1/api'
  config.timeout = 6000

  // 除登录业务以外都要携带token
  if(!allowToken.includes(config.url)){
    config.headers['token'] = 'Bearer '+store.getters.getToken
  }

  return config
}, error => Promise.reject(error)
)

// 请求
export default ({ url, method = 'get', data = {} }) => {
  return axios({
    url,
    method,
    data
  })
}
